package com.ruoyi.report_lqn.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_lqn.domain.bo.ReportLqnRhlqwdxjlbBsInfoBo;
import com.ruoyi.report_lqn.domain.vo.ReportLqnRhlqwdxjlbBsInfoVo;
import com.ruoyi.report_lqn.domain.ReportLqnRhlqwdxjlbBsInfo;
import com.ruoyi.report_lqn.mapper.ReportLqnRhlqwdxjlbBsInfoMapper;
import com.ruoyi.report_lqn.service.IReportLqnRhlqwdxjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 乳化沥青储存稳定性、破乳速度试验检测记录（一）Service业务层处理
 *
 * @author tll
 * @date 2024-09-12
 */
@RequiredArgsConstructor
@Service
public class ReportLqnRhlqwdxjlbBsInfoServiceImpl implements IReportLqnRhlqwdxjlbBsInfoService {

    private final ReportLqnRhlqwdxjlbBsInfoMapper baseMapper;

    /**
     * 查询乳化沥青储存稳定性、破乳速度试验检测记录（一）
     */
    @Override
    @FIllBasicInfo
    public ReportLqnRhlqwdxjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询乳化沥青储存稳定性、破乳速度试验检测记录（一）列表
     */
    @Override
    public TableDataInfo<ReportLqnRhlqwdxjlbBsInfoVo> queryPageList(ReportLqnRhlqwdxjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportLqnRhlqwdxjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportLqnRhlqwdxjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询乳化沥青储存稳定性、破乳速度试验检测记录（一）列表
     */
    @Override
    public List<ReportLqnRhlqwdxjlbBsInfoVo> queryList(ReportLqnRhlqwdxjlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportLqnRhlqwdxjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportLqnRhlqwdxjlbBsInfo> buildQueryWrapper(ReportLqnRhlqwdxjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLqnRhlqwdxjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportLqnRhlqwdxjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportLqnRhlqwdxjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportLqnRhlqwdxjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportLqnRhlqwdxjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportLqnRhlqwdxjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportLqnRhlqwdxjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportLqnRhlqwdxjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportLqnRhlqwdxjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportLqnRhlqwdxjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, ReportLqnRhlqwdxjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportLqnRhlqwdxjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportLqnRhlqwdxjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportLqnRhlqwdxjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportLqnRhlqwdxjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportLqnRhlqwdxjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportLqnRhlqwdxjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportLqnRhlqwdxjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportLqnRhlqwdxjlbBsInfo::getBaobmc, bo.getBaobmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportLqnRhlqwdxjlbBsInfo::getBaobbh, bo.getBaobbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportLqnRhlqwdxjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportLqnRhlqwdxjlbBsInfo::getJiancr, bo.getJiancr());
        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportLqnRhlqwdxjlbBsInfo::getJilr, bo.getJilr());
        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportLqnRhlqwdxjlbBsInfo::getFuhr, bo.getFuhr());
        lqw.eq(bo.getRiq() != null, ReportLqnRhlqwdxjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportLqnRhlqwdxjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportLqnRhlqwdxjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportLqnRhlqwdxjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getQuydd()), ReportLqnRhlqwdxjlbBsInfo::getQuydd, bo.getQuydd());
        lqw.eq(StringUtils.isNotBlank(bo.getRuhlqpzdh()), ReportLqnRhlqwdxjlbBsInfo::getRuhlqpzdh, bo.getRuhlqpzdh());
        lqw.eq(StringUtils.isNotBlank(bo.getRuhlqcd()), ReportLqnRhlqwdxjlbBsInfo::getRuhlqcd, bo.getRuhlqcd());
        lqw.eq(StringUtils.isNotBlank(bo.getRuhlqzlbh()), ReportLqnRhlqwdxjlbBsInfo::getRuhlqzlbh, bo.getRuhlqzlbh());
        lqw.eq(StringUtils.isNotBlank(bo.getWendxSycs1()), ReportLqnRhlqwdxjlbBsInfo::getWendxSycs1, bo.getWendxSycs1());
        lqw.eq(StringUtils.isNotBlank(bo.getWendxBw1()), ReportLqnRhlqwdxjlbBsInfo::getWendxBw1, bo.getWendxBw1());
        lqw.eq(bo.getWendxM11() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM11, bo.getWendxM11());
        lqw.eq(bo.getWendxM21() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM21, bo.getWendxM21());
        lqw.eq(bo.getWendxM31() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM31, bo.getWendxM31());
        lqw.eq(bo.getWendxM41() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM41, bo.getWendxM41());
        lqw.eq(bo.getWendxM51() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM51, bo.getWendxM51());
        lqw.eq(bo.getWendxClwhl1() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxClwhl1, bo.getWendxClwhl1());
        lqw.eq(bo.getWendxCz1() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxCz1, bo.getWendxCz1());
        lqw.eq(StringUtils.isNotBlank(bo.getWendxSycs2()), ReportLqnRhlqwdxjlbBsInfo::getWendxSycs2, bo.getWendxSycs2());
        lqw.eq(StringUtils.isNotBlank(bo.getWendxBw2()), ReportLqnRhlqwdxjlbBsInfo::getWendxBw2, bo.getWendxBw2());
        lqw.eq(bo.getWendxM12() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM12, bo.getWendxM12());
        lqw.eq(bo.getWendxM22() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM22, bo.getWendxM22());
        lqw.eq(bo.getWendxM32() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM32, bo.getWendxM32());
        lqw.eq(bo.getWendxM42() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM42, bo.getWendxM42());
        lqw.eq(bo.getWendxM52() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM52, bo.getWendxM52());
        lqw.eq(bo.getWendxClwhl2() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxClwhl2, bo.getWendxClwhl2());
        lqw.eq(bo.getWendxCz2() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxCz2, bo.getWendxCz2());
        lqw.eq(StringUtils.isNotBlank(bo.getWendxSycs3()), ReportLqnRhlqwdxjlbBsInfo::getWendxSycs3, bo.getWendxSycs3());
        lqw.eq(StringUtils.isNotBlank(bo.getWendxBw3()), ReportLqnRhlqwdxjlbBsInfo::getWendxBw3, bo.getWendxBw3());
        lqw.eq(bo.getWendxM13() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM13, bo.getWendxM13());
        lqw.eq(bo.getWendxM23() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM23, bo.getWendxM23());
        lqw.eq(bo.getWendxM33() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM33, bo.getWendxM33());
        lqw.eq(bo.getWendxM43() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM43, bo.getWendxM43());
        lqw.eq(bo.getWendxM53() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM53, bo.getWendxM53());
        lqw.eq(bo.getWendxClwhl3() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxClwhl3, bo.getWendxClwhl3());
        lqw.eq(bo.getWendxCz3() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxCz3, bo.getWendxCz3());
        lqw.eq(StringUtils.isNotBlank(bo.getWendxSycs4()), ReportLqnRhlqwdxjlbBsInfo::getWendxSycs4, bo.getWendxSycs4());
        lqw.eq(StringUtils.isNotBlank(bo.getWendxBw4()), ReportLqnRhlqwdxjlbBsInfo::getWendxBw4, bo.getWendxBw4());
        lqw.eq(bo.getWendxM14() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM14, bo.getWendxM14());
        lqw.eq(bo.getWendxM24() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM24, bo.getWendxM24());
        lqw.eq(bo.getWendxM34() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM34, bo.getWendxM34());
        lqw.eq(bo.getWendxM44() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM44, bo.getWendxM44());
        lqw.eq(bo.getWendxM54() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxM54, bo.getWendxM54());
        lqw.eq(bo.getWendxClwhl4() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxClwhl4, bo.getWendxClwhl4());
        lqw.eq(bo.getWendxCz4() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxCz4, bo.getWendxCz4());
        lqw.eq(bo.getWendxPjz() != null, ReportLqnRhlqwdxjlbBsInfo::getWendxPjz, bo.getWendxPjz());
        lqw.eq(StringUtils.isNotBlank(bo.getChucsj1()), ReportLqnRhlqwdxjlbBsInfo::getChucsj1, bo.getChucsj1());
        lqw.eq(StringUtils.isNotBlank(bo.getChucsj2()), ReportLqnRhlqwdxjlbBsInfo::getChucsj2, bo.getChucsj2());
        lqw.eq(StringUtils.isNotBlank(bo.getChucsj3()), ReportLqnRhlqwdxjlbBsInfo::getChucsj3, bo.getChucsj3());
        lqw.eq(StringUtils.isNotBlank(bo.getChucsj4()), ReportLqnRhlqwdxjlbBsInfo::getChucsj4, bo.getChucsj4());
        lqw.eq(StringUtils.isNotBlank(bo.getChucsj5()), ReportLqnRhlqwdxjlbBsInfo::getChucsj5, bo.getChucsj5());
        lqw.eq(StringUtils.isNotBlank(bo.getWendfw1()), ReportLqnRhlqwdxjlbBsInfo::getWendfw1, bo.getWendfw1());
        lqw.eq(StringUtils.isNotBlank(bo.getWendfw2()), ReportLqnRhlqwdxjlbBsInfo::getWendfw2, bo.getWendfw2());
        lqw.eq(StringUtils.isNotBlank(bo.getWendfw3()), ReportLqnRhlqwdxjlbBsInfo::getWendfw3, bo.getWendfw3());
        lqw.eq(StringUtils.isNotBlank(bo.getWendfw4()), ReportLqnRhlqwdxjlbBsInfo::getWendfw4, bo.getWendfw4());
        lqw.eq(StringUtils.isNotBlank(bo.getWendfw5()), ReportLqnRhlqwdxjlbBsInfo::getWendfw5, bo.getWendfw5());
        lqw.eq(StringUtils.isNotBlank(bo.getPorsdZb1()), ReportLqnRhlqwdxjlbBsInfo::getPorsdZb1, bo.getPorsdZb1());
        lqw.eq(bo.getPorsdZl1() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdZl1, bo.getPorsdZl1());
        lqw.eq(bo.getPorsdSl1() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdSl1, bo.getPorsdSl1());
        lqw.eq(bo.getPorsdYl1() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdYl1, bo.getPorsdYl1());
        lqw.eq(StringUtils.isNotBlank(bo.getPorsdMs1()), ReportLqnRhlqwdxjlbBsInfo::getPorsdMs1, bo.getPorsdMs1());
        lqw.eq(bo.getPorsdSd1() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdSd1, bo.getPorsdSd1());
        lqw.eq(StringUtils.isNotBlank(bo.getPorsdZb2()), ReportLqnRhlqwdxjlbBsInfo::getPorsdZb2, bo.getPorsdZb2());
        lqw.eq(bo.getPorsdZl2() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdZl2, bo.getPorsdZl2());
        lqw.eq(bo.getPorsdSl2() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdSl2, bo.getPorsdSl2());
        lqw.eq(bo.getPorsdYl2() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdYl2, bo.getPorsdYl2());
        lqw.eq(StringUtils.isNotBlank(bo.getPorsdMs2()), ReportLqnRhlqwdxjlbBsInfo::getPorsdMs2, bo.getPorsdMs2());
        lqw.eq(bo.getPorsdSd2() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdSd2, bo.getPorsdSd2());
        lqw.eq(bo.getPorsdPjz() != null, ReportLqnRhlqwdxjlbBsInfo::getPorsdPjz, bo.getPorsdPjz());
        return lqw;
    }

    /**
     * 新增乳化沥青储存稳定性、破乳速度试验检测记录（一）
     */
    @Override
    public Boolean insertByBo(ReportLqnRhlqwdxjlbBsInfoBo bo) {
        ReportLqnRhlqwdxjlbBsInfo add = BeanUtil.toBean(bo, ReportLqnRhlqwdxjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改乳化沥青储存稳定性、破乳速度试验检测记录（一）
     */
    @Override
    public Boolean updateByBo(ReportLqnRhlqwdxjlbBsInfoBo bo) {
        ReportLqnRhlqwdxjlbBsInfo update = BeanUtil.toBean(bo, ReportLqnRhlqwdxjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportLqnRhlqwdxjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除乳化沥青储存稳定性、破乳速度试验检测记录（一）
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
